<template>
  <div style="width: 100%; display: flex; justify-content: center">
    <div class="ad" :class="{ mobile: mobile === 'false' ? false : true }">
      <div
        v-for="item of props.dataList"
        :key="item.id"
        style="width: 100%"
        @click="toTarget(item.targetUrl)"
      >
        <el-image :src="item.imgUrl" :alt="item.title" class="ad-img" lazy>
          <template #error>
            <div class="image-slot">
              <el-icon><icon-picture /></el-icon>
            </div>
          </template>
        </el-image>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from "vue";

const props = defineProps({
  dataList: {
    type: Array,
    default: () => [],
  },
});

const mobile = localStorage.getItem("mobile");

const toTarget = (url) => {
  window.open(url);
};
</script>

<style scoped lang="scss">
.ad {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.mobile {
  width: 70% !important;
}

.ad-img {
  height: 80px;
  width: 100%;
}
</style>
